home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows 95 API Bible
/
Windows 95 API Bible 3 Disc Set.iso
/
Win32 API Bible Book 1 of 3
/
CHAPTE25
/
EX10.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-23
|
3KB
|
77 lines
#include <genstub.c>
// Add these options to the menu.
#define IDM_IDLE 401
#define IDM_NORMAL 402
#define IDM_HIGH 403
#define IDM_REALTIME 404
// Function that wastes CPU time.
DWORD GoWasteSomeCPU(void)
{
long i, j;
DWORD dwTicksNow = GetTickCount( );
for ( i = 0; i < 100000; i ++ )
for ( j = 0; j < 1000; j ++ );
return GetTickCount( ) - dwTicksNow;
}
// Windows message procedure.
LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch ( uMsg )
{
case WM_COMMAND: // process menu items
{
DWORD dwPriorityClass = 0;
switch ( LOWORD( wParam ) )
{
case IDM_IDLE:
dwPriorityClass = IDLE_PRIORITY_CLASS;
break;
case IDM_NORMAL:
dwPriorityClass = NORMAL_PRIORITY_CLASS;
break;
case IDM_HIGH:
dwPriorityClass = HIGH_PRIORITY_CLASS;
break;
case IDM_REALTIME:
dwPriorityClass = REALTIME_PRIORITY_CLASS;
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
}
if (dwPriorityClass != 0) {
// Set the priority class.
SetPriorityClass(GetCurrentProcess(), dwPriorityClass);
SendMessage( hWnd, WM_USER, 0, GoWasteSomeCPU() );
}
}
break;
case WM_USER:
{
TCHAR szBuffer[128];
static int iRow = 0;
HDC hDC = GetDC( hWnd );
DWORD dwPrCls = GetPriorityClass( GetCurrentProcess( ) );
wsprintf( szBuffer, "Priority Class is %s, Time spent: %ld",
( dwPrCls==NORMAL_PRIORITY_CLASS ) ? "NORMAL" :
( ( dwPrCls==REALTIME_PRIORITY_CLASS ) ? "REALTIME" :
( ( dwPrCls==HIGH_PRIORITY_CLASS ) ? "HIGH" : "IDLE" ) ),
lParam );
TextOut( hDC, 0, iRow, szBuffer, lstrlen( szBuffer ) );
ReleaseDC( hWnd, hDC );
iRow += 20;
if ( iRow > 220 )
iRow = 0;
}
break;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
default:
return (DefWindowProc(hWnd, uMsg, wParam, lParam));
}
return (NULL);
}